<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 订单表
 * @ author: zuorenci
 * @ email: 904725327@qq.com
 * @ date: 2017/10/24 21:01
 */
class Industry extends Model
{
    public $timestamps    = false;
    protected $table      = 'industry';
    protected $primaryKey = 'industryID';
    protected $fillable   = [
        'industryID', //行业id
        'name', //名字
        'PID', //父id
        'type', //类型
        'time', //时间
        'id', //添加人id
        'icon', //图标
        'orderby', //排序
        'rate', //平台抽成比例
        'is_hot', //热门 1为热门 0为不是热门
        'switch', //开关 1为关 2为开
        'icon_oss',
    ];

    protected $casts = ['icon'];

    public function getIconAttribute($value)
    {
        return \App\Library\HandleFile::handleFilePath($value, $this->icon_oss);
    }

    //下级分类
    public function industries()
    {
        return $this->hasMany('App\\Models\\Industry', 'PID', 'industryID')->where('switch', 2);
    }
}
